<template>
  <div class="see-points-container">
    <el-form class="search-form" ref="form" :model="searchForm" label-width="80px">
      <el-form-item label="单位名称">
        <el-input v-model="searchForm.unitName" placeholder="请输入单位名称"></el-input>
      </el-form-item>
      <el-form-item label="单位类型">
        <el-select v-model="searchForm.unitType" placeholder="请选择单位类型">
          <el-option
            v-for="type in unitTypeOptions"
            :key="type.unittypeId"
            :label="type.unittypeName"
            :value="type.unittypeId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button size="mini" icon="el-icon-refresh" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      stripe
      :data="deductTableData"
      style="width: 100%">
      <el-table-column
        align="center"
        prop="index"
        label="序号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="unitName"
        label="单位名称"
        show-overflow-tooltip
        width="180">
      </el-table-column>
      <el-table-column
        prop="unitNum"
        label="中签次数">
      </el-table-column>
      <el-table-column
        prop="unitRepresentative"
        label="法定代表人">
      </el-table-column>
      <el-table-column
        prop="unitRepresentativePhone"
        label="法定代表人联系电话">
      </el-table-column>
      <el-table-column
        prop="unitLinkman"
        label="联系人">
      </el-table-column>
      <el-table-column
        prop="unitPhone"
        label="联系电话">
      </el-table-column>
      <el-table-column
        prop="unitType"
        label="单位类型"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{scope.row.unitType | approveStatusFormat}}
        </template>
      </el-table-column>
      <el-table-column
        prop="forbidden"
        label="单位状态">
        <template slot-scope="scope">
          {{scope.row.forbidden === '1' ? '禁用' :'扣分超标'}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="goDetailDialog(scope.row)"
          >查看详情</el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
      class="pagination"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount">
    </el-pagination>

    <el-dialog
      title="单位详情"
      :visible.sync="detailDialogVisible"
      width="50%"
    >
      <detailDialog :detailForm="detailForm" :unitTypeOptions="unitTypeOptions"></detailDialog>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="detailDialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import detailDialog from "@/views/unit/extract/seePoints/components/detailDialog";
import {listUnittype} from "@/api/unit/unittype";
import {getUnit} from "@/api/unit/unit";
import {getSeePonitsList,getUnitDetail} from "@/api/unit/seePoints";
export default {
  name: "SeePointsIndex",
  components:{
    detailDialog
  },
  data(){
    return {
      searchForm:{
        unitName:'',
        unitType:''
      },
      unitTypeOptions:[],// 单位类型下拉数据
      deductTableData: [{
        unitSort:1,
        unitName: '名称1',
        unitNum: '1',
        unitRepresentative: '张三',
        unitRepresentativePhone:'13911111111',
        unitLinkman:'张三',
        unitPhone:'13911111111',
        unitType:'招标代理',
        forbidden:'0',
        badPoints:2
      }, {
        unitSort:2,
        unitName: '名称2',
        unitNum: '1',
        unitRepresentative: '张三',
        unitRepresentativePhone:'13922222222',
        unitLinkman:'张三',
        unitPhone:'13911111111',
        unitType:'招标代理',
        forbidden:'0',
        badPoints:2
      }, {
        unitSort:3,
        unitName: '名称3',
        unitNum: '1',
        unitRepresentative: '张三',
        unitRepresentativePhone:'13911111111',
        unitLinkman:'张三',
        unitPhone:'13911111111',
        unitType:'招标代理',
        forbidden:'0',
        badPoints:2
      }, {
        unitSort:4,
        unitName: '名称4',
        unitNum: '1',
        unitRepresentative: '张三',
        unitRepresentativePhone:'13911111111',
        unitLinkman:'张三',
        unitPhone:'13911111111',
        unitType:'招标代理',
        forbidden:'0',
        badPoints:2
      }],
      currentPage:1,
      totalCount:0,
      pageSize:10,
      detailDialogVisible: false,
      detailForm:{}
    }
  },
  methods:{
    async getUnitTypes(){
     const res =  await listUnittype()
      this.unitTypeOptions = res.rows
    },
    handleSizeChange(val){
      console.log('handleSizeChange',val)
      this.pageSize = val
      this.currentPage = 1
      this.loadSeePonitsList()
    },
    handleCurrentChange(val){
      this.currentPage = val
      this.loadSeePonitsList()
    },
    // 搜索
    search(){
      this.loadSeePonitsList()
    },
    // 重置
    reset(){
      this.searchForm.unitName = ''
      this.searchForm.unitType = ''
      this.loadSeePonitsList()
    },
    // 获取列表
    async loadSeePonitsList(){
      const params = {}
      params.pageNum = this.currentPage
      params.pageSize = this.pageSize
      params.unitName = this.searchForm.unitName
      params.unitType = this.searchForm.unitType
      const res = await getSeePonitsList(params)
      this.deductTableData = res.rows
      this.totalCount = res.total
      this.deductTableData.forEach((item,i) => {
        item.index = (this.currentPage -1) * this.pageSize + i + 1
      })
    },
    // 获取详情
    async goDetailDialog(row){
      const res = await getUnitDetail(row.unitId)
      this.detailForm = res.data
      this.detailDialogVisible = true
    }
  },
  created() {
    this.getUnitTypes()
    this.loadSeePonitsList()
  },
  filters:{
    approveStatusFormat(unitType){
      switch(unitType){
        case 1:
          return "招标代理"
          break
        case 2:
          return "施工图审查（含勘察报告审查）"
          break
        case 3:
          return "预结算（含施工图预算清单编制、工程变更审核、结算内部）"
          break
        case 4:
          return "工程财务决算"
          break
        case 5:
          return "工程设计"
          break
        case 6:
          return "工程勘察（含各阶段勘察工作、勘察外业见证）"
          break
        case 7:
          return "工程监理"
          break
        case 8:
          return "工程检测单位"
          break
        case 9:
          return "预结算（跟踪审计）"
          break
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.see-points-container{
  padding: 20px;
  .search-form{
    display: flex;
  }
  .pagination{
    padding-top: 20px;
    display: flex;
    justify-content: flex-end;
  }
}
::v-deep .el-table{
  max-height: 600px;
  overflow: auto;
}
</style>
